home *** CD-ROM | disk | FTP | other *** search
/ Experimental BBS Explossion 3 / Experimental BBS Explossion III.iso / compress / zipcmnt.zip / ZIPCMNT.PAS < prev   
Pascal/Delphi Source File  |  1993-05-15  |  4KB  |  184 lines

  1. { Zip file comment adder 1.0                   }
  2. { Copyright (c) 1990 McBrine Computer Products }
  3. { See below for more info                      }
  4.  
  5. program zipcomment(zipfile,cmntfile,output);
  6. uses
  7.  dos;
  8. type                              { Comment is stored on the heap }
  9.  ptr=^foo;                        { Note TP4.0 will not accept 0..65535 }
  10.  foo=record                       { as a range for an array! }
  11.   bar:array[0..65534] of byte
  12.  end;                                  
  13. var
  14.  zipfile,cmntfile:file of byte;
  15.  zippat,cmntname:string[80];
  16.  x,y,z:longint;
  17.  m,n,o,clength:word;
  18.  a,b,t,e:byte;
  19.  comment:ptr;
  20.  scanz:searchrec;
  21.  
  22. procedure sz;
  23.  begin                            { Too simple to be a procedure in its }
  24.   seek(zipfile,x)                 { own right, it seems; but it results in }
  25.  end;                             { a much shorter compiled program }
  26.  
  27. procedure rnp;
  28.  begin
  29.   read(zipfile,a,b)
  30.  end;
  31.  
  32. function rno:word;
  33.  begin
  34.   rnp;
  35.   rno:=a+256*b
  36.  end;
  37.  
  38. procedure gettype;
  39.  begin
  40.   x:=x+4;
  41.   t:=0;
  42.   rnp;
  43.   if (a=80) and (b=75) then
  44.    begin
  45.     rnp;
  46.     case a+b of
  47.       7:t:=1;
  48.       3:t:=2;
  49.      11:t:=3
  50.     end
  51.    end
  52.  end;
  53.  
  54. procedure error1;
  55.  begin
  56.   writeln('Zip File Comment Adder 1.0');
  57.   writeln('by William J. McBrine III');
  58.   writeln('Copyright (c) 1990 McBrine Computer Products');
  59.   writeln;
  60.   writeln('Syntax is:');
  61.   writeln;
  62.   writeln('ZIPCMNT zipfile[.zip] cmntfile.ext [/l]');
  63.   writeln;
  64.   writeln('"Zipfile" is the filespec to add a comment to, and may include wildcards. The');
  65.   writeln('extension ".ZIP" is assumed if none is given. "Cmntfile.ext" is the file con-');
  66.   writeln('taining the comment; can be any file under 64K (use "NUL" to strip comments).');
  67.   writeln('"/l" option (must be third parameter) adds in two <CR><LF>s before the comment.');
  68.   writeln;
  69.   writeln('This program is free software, distributed under the terms of the GNU General');
  70.   writeln('Public License as published by the Free Software Foundation, version 1. It is');
  71.   writeln('distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY. See');
  72.   writeln('LICENSE.DOC for details. It should have come with this program; if not, write:');
  73.   writeln;
  74.   writeln('Free Software Foundation, Inc. / 675 Massachusetts Avenue / Cambridge, MA 02139');
  75.   writeln;
  76.   writeln('author: William J. McBrine III / 514 S. Jackson St. / Salisbury, NC 28144-5428');
  77.   writeln('email : WILLIAM MCBRINE on HomeBoy''s Digital Undergound, (704) 637-2342  3-24');
  78.   writeln('                         & The Big Byte, (704) 279-2295  3-96 dual');
  79.   halt
  80.  end;
  81.  
  82. procedure skipfile;
  83.  begin
  84.   x:=x+14;
  85.   sz;
  86.   y:=rno;
  87.   z:=rno;
  88.   y:=y+65536*z;
  89.   x:=x+8;
  90.   sz;
  91.   m:=rno;
  92.   n:=rno;
  93.   x:=x+y+m+n+4;
  94.   sz
  95.  end;
  96.  
  97. procedure skipdir;
  98.  begin
  99.   x:=x+24;
  100.   sz;
  101.   m:=rno;
  102.   n:=rno;
  103.   o:=rno;
  104.   x:=x+m+n+o+18;
  105.   sz
  106.  end;
  107.  
  108. procedure readcmnt;
  109.  begin
  110.   writeln('Reading comment file: ',cmntname);
  111.   assign(cmntfile,cmntname);
  112.   reset(cmntfile);
  113.   clength:=filesize(cmntfile);
  114.   mark(comment);
  115.   getmem(comment,clength);
  116.   if clength>0 then
  117.    with comment^ do for m:=0 to clength-1 do read(cmntfile,bar[m]);
  118.   close(cmntfile)
  119.  end;
  120.  
  121. procedure onezip;
  122.  begin
  123.   writeln('Commenting: ',scanz.name);
  124.   assign(zipfile,scanz.name);
  125.   reset(zipfile);
  126.   if filesize(zipfile)<4 then t:=0
  127.   else
  128.    begin
  129.     x:=0;
  130.     repeat
  131.      gettype;
  132.      case t of
  133.       1:skipfile;
  134.       2:skipdir
  135.      end
  136.     until (t=3) or (t=0)
  137.    end;
  138.   if t=0 then
  139.    begin
  140.     writeln(' I can''t read this ZIP file!');
  141.     close(zipfile)
  142.    end
  143.   else
  144.    begin
  145.     x:=x+16;
  146.     sz;
  147.  
  148. { We're now at the zipfile comment length field }
  149.  
  150.     m:=clength+e;
  151.     a:=lo(m);
  152.     b:=hi(m);
  153.     write(zipfile,a,b);
  154.     if e=4 then
  155.      begin
  156.       a:=13;
  157.       b:=10;
  158.       write(zipfile,a,b,a,b)
  159.      end;
  160.     if clength>0 then
  161.      with comment^ do for n:=0 to clength-1 do write(zipfile,bar[n]);
  162.     truncate(zipfile);
  163.     close(zipfile)
  164.    end
  165.  end;
  166.  
  167. begin
  168.  e:=0;
  169.  if paramcount=3 then
  170.   if paramstr(3)='/l' then e:=4
  171.   else
  172.  else if paramcount<>2 then error1;
  173.  zippat:=paramstr(1);
  174.  cmntname:=paramstr(2);
  175.  if pos('.',zippat)=0 then zippat:=concat(zippat,'.zip');
  176.  readcmnt;
  177.  findfirst(zippat,anyfile,scanz);
  178.  if doserror=0 then
  179.   repeat
  180.    onezip;
  181.    findnext(scanz)
  182.   until doserror<>0
  183. end.
  184.